package ups.glre.news.struts.form;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts.action.ActionForm;

import ups.glre.news.model.Category;

public class SubscriptionForm extends ActionForm{
	private static final long serialVersionUID = 5949940457830681628L;
	
	private List<Category> subscribedCategories = new ArrayList<Category>();
	private List<Category> categories = new ArrayList<Category>();
	private String[] selectedCategories;
	
	private int userId;
	private int categoryId;
	private String propertySubscribe;
	private String methodToCall;	
	
	public String getMethodToCall() {
		return methodToCall;
	}
	
	public void setMethodToCall(String methodToCall) {
		this.methodToCall = methodToCall;
	}
	
	public boolean isSubscibedCategory(int categoriesId){
		
		Category category = new Category("");
		category.setCategoryId(categoriesId);
		
		return subscribedCategories.contains(category);
	}
	
	public List<Category> getSubscribedCategories() {
		return subscribedCategories;
	}
	public void setSubscribedCategories(List<Category> subscribedCategories) {
		this.subscribedCategories = subscribedCategories;
		selectedCategories = new String[subscribedCategories.size()];
		initSelectedItem();
	}
	
	
	private void initSelectedItem() {		
		int count = 0; 
		while (count < this.selectedCategories.length){
		      Category category = subscribedCategories.get(count);
		      
		      selectedCategories[count] = ""+category.getCategoryId();
		      
		      count++;
		}
		
	}

	public String[] getSelectedCategories() {
		return selectedCategories;
	}

	public void setSelectedCategories(String[] selectedCategories) {
		this.selectedCategories = selectedCategories;
	}

	public int getUserId() {
		return userId;
	}
	
	public void setUserId(int userId) {
		this.userId = userId;
	}
	
	public int getCategoryId() {
		return categoryId;
	}
	
	public void setCategoryId(int categoryId) {
		this.categoryId = categoryId;
	}
	
	public String getPropertySubscribe() {
		return propertySubscribe;
	}
	
	public void setPropertySubscribe(String propertySubscribe) {
		this.propertySubscribe = propertySubscribe;
	}

	public List<Category> getCategories() {
		return categories;
	}

	public void setCategories(List<Category> categories) {
		this.categories = categories;
	}
	
}
